package com.lkl.demo.provider.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {

    /**
     * 用户注册
     */
    @PostMapping("/regist")
    public Map<String, String> register(String username, String password) throws InterruptedException {
        long start = System.currentTimeMillis();
        // 1、数据库新增数据
        Thread.sleep(1000);
        System.out.println("数据库新增成功，" + username);
        // 2、调用外部接口，发送短信
        Thread.sleep(1000);
        System.out.println("短信发送成功");
        // 3、调用外部接口，发送邮箱
        Thread.sleep(1100);
        System.out.println("邮箱发送成功");

        HashMap<String, String> map = new HashMap<>();
        map.put("msg", "注册成功");
        map.put("code", "200");
        map.put("costTime", System.currentTimeMillis() - start + "ms");
        return map;
    }

    /**
     * 用户注销
     */
    @PutMapping("/logout")
    public Map<String, String> logout(String username, String password) throws InterruptedException {
        long start = System.currentTimeMillis();
        // 1、数据库修改数据
        Thread.sleep(1000);
        System.out.println("数据库修改成功，" + username);
        // 2、调用外部接口，发送短信
        Thread.sleep(1000);
        System.out.println("注销短信发送成功");
        // 3、调用外部接口，发送邮箱
        Thread.sleep(1100);
        System.out.println("注销邮箱发送成功");

        HashMap<String, String> map = new HashMap<>();
        map.put("msg", "注销成功");
        map.put("code", "200");
        map.put("costTime", System.currentTimeMillis() - start + "ms");
        return map;
    }
}
